#include "StoneFallingPoint.h"
#include "PlayState.h"


CStoneFallingPoint::CStoneFallingPoint(D3DXVECTOR2 pos, int id, int typeID) : CMoveableObject(pos, id, typeID)
{

	for (int i = 0; i < 2; i++)
	{
		m_stones[i] = new CStoneFalling(pos, i, ID_STONE_FALLING);
	}

	m_nCurStoneIndex = 0;
}


CStoneFallingPoint::~CStoneFallingPoint()
{
	if (m_stones[0])
		delete m_stones[0];
	if (m_stones[1])
		delete m_stones[1];
}

void CStoneFallingPoint::Update(float timeFrame)
{
	D3DXVECTOR2 vpPos = CViewport::GetInstance()->GetPosition();
	Box vpBox = { vpPos.x + 50, vpPos.y, SCREEN_WIDTH, SCREEN_HEIGHT, 0.0f, 0.0f };
	Box pointBox = { m_pos.x, m_pos.y, 10, 10, 0.0f, 0.0f };
	m_bInViewPort = pointBox.IsInside(vpBox);

	if (m_bInViewPort)
	{
		if (m_stones[m_nCurStoneIndex]->GetPos().y + 30.0f < vpPos.y - SCREEN_HEIGHT)
		{
			m_stones[m_nCurStoneIndex]->Reset();
			m_nCurStoneIndex = (m_nCurStoneIndex + 1) % 2;
		}

		m_stones[m_nCurStoneIndex]->Update(timeFrame);
	}
}

void CStoneFallingPoint::UpdateCollision(vector<CGameObject*> vecGameObjs, float timeFrame)
{
	if (m_bInViewPort)
		m_stones[m_nCurStoneIndex]->UpdateCollision(vecGameObjs, timeFrame);
}

void CStoneFallingPoint::Draw()
{
	if (m_bInViewPort)
		m_stones[m_nCurStoneIndex]->Draw();
}

CGameObject* CStoneFallingPoint::GetCurrentStone()
{
	return m_stones[m_nCurStoneIndex];
}